package com.core.website.service.impl;

import com.core.website.entity.CoreDutyRecordInfo;
import com.core.website.mapper.CoreDutyRecordInfoMapper;
import com.core.website.service.CoreDutyRecordInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class CoreDutyRecordInfoImpl implements CoreDutyRecordInfoService {
    @Autowired
    CoreDutyRecordInfoMapper coreDutyRecordInfoMapper;
    @Override
    public String insertCoreDutyRecordInfo(CoreDutyRecordInfo coreDutyRecordInfo) {
        // 根据内容id查询一下
        if(StringUtils.isNotEmpty(coreDutyRecordInfo.getId())){
            coreDutyRecordInfoMapper.updateCoreDutyRecordInfo(coreDutyRecordInfo);
            return coreDutyRecordInfo.getId();
        }else{
            coreDutyRecordInfo.setId(UUID.randomUUID().toString().toUpperCase().replace("-", ""));
            coreDutyRecordInfoMapper.insertCoreDutyRecordInfo(coreDutyRecordInfo);
            return coreDutyRecordInfo.getId(); // 返回id 直接存起来
        }
    }

    @Override
    public CoreDutyRecordInfo selectCoreDutyRecordInfoById(String id) {
        return coreDutyRecordInfoMapper.selectCoreDutyRecordInfoById(id);
    }

    @Override
    public CoreDutyRecordInfo selectCoreDutyRecordInfoByContentId(String contentId) {
        return coreDutyRecordInfoMapper.selectCoreDutyRecordInfoByContentId(contentId);
    }
}
